home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / beginner_gadgets / gadget2.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  3KB  |  105 lines

  1. /**************************************************************************
  2. *****                       Gadget Demo 2                             *****
  3. *****                                                                 *****
  4. *****                     by John J. Karcher                          *****
  5. *****                                                                 *****
  6. *****                       4 August 1992                             *****
  7. *****                       10 Jan 1993 mvk                                          *****
  8. *****                                                                 *****
  9. **************************************************************************/
  10.  
  11. /*
  12.    This program opens up a window with a single gadget in it, using
  13.    egsgadbox.library.  This one is a little smarter; it waits for
  14.    the user to hit the close gadget before dying.  It also prints
  15.    a little message to the console if you click on the action gadget.
  16.  
  17.    This demonstrates how to get a close gadget, deal with idcmp
  18.    messages, and react to action gadget messages.
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <exec/types.h>
  23. #include <egs/egsintui.h>
  24. #include <egs/egsgadbox.h>
  25. #include <proto/all.h>
  26. #include <egs/proto/all.h>
  27.  
  28. struct EI_Window  *CreateWindow(void);
  29.  
  30. #define  ACTION_GAD_ID     1000
  31.  
  32.  
  33. struct Library *EGSIntuiBase;
  34. struct Library *EGBBase;
  35.  
  36. struct EB_GadContextNode   *GadCon;
  37.  
  38.  
  39. struct EI_Window  *CreateWindow(void)
  40. {
  41.    struct EI_Window           *ret = NULL;
  42.    EB_GadBoxPtr               root;
  43.  
  44.    if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
  45.      {
  46.       if (root = EB_CreateTextAction(GadCon, "Push Me", ACTION_GAD_ID, EB_FILL_ALL))
  47.         {
  48.          if (EB_ProcessGadBoxes(GadCon, root))
  49.            {
  50.             GadCon->NewWin->Title              = "EGS Gadget Demo 2";
  51.             GadCon->NewWin->IDCMPFlags        |= (EI_iCLOSEWINDOW | EI_iGADGETUP);
  52.             GadCon->NewWin->Flags             |= EI_WINDOWCENTER;
  53.             GadCon->NewWin->Bordef.SysGadgets |= EI_WINDOWCLOSE;
  54.             GadCon->NewWin->Width = 200;
  55.             GadCon->NewWin->Height= 100;
  56.               ret = EI_OpenWindow(GadCon->NewWin);
  57.            }
  58.         }
  59.      }
  60.  
  61.    return ret;
  62. }
  63.  
  64. main()
  65. {
  66.    struct EI_Window     *Win;
  67.    struct EI_EIntuiMsg  *IMsg;
  68.    struct EI_Gadget     *TempGad;
  69.    BYTE  quit = 0;
  70.  
  71.    if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
  72.      {
  73.       if (EGBBase = OpenLibrary("egsgadbox.library", 0))
  74.         {
  75.          if (Win = CreateWindow())
  76.            {
  77.             while (!quit)
  78.               {
  79.                WaitPort(Win->UserPort);
  80.                if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
  81.                  {
  82.                   if (IMsg->Class == EI_iCLOSEWINDOW)
  83.                     {
  84.                      quit = 1;
  85.                     }
  86.                   if (IMsg->Class == EI_iGADGETUP)
  87.                     {
  88.                      TempGad = (struct EI_Gadget *)IMsg->IAddress;
  89.                      if (TempGad->GadgetID == ACTION_GAD_ID)
  90.                        {
  91.                         printf("You pressed me!\n");
  92.                        }
  93.                     }
  94.                   ReplyMsg((struct Message *)IMsg);
  95.                  }
  96.               }
  97.            }
  98.          if (Win) EI_CloseWindow(Win);
  99.          if (GadCon) EB_DeleteGadContext(GadCon);
  100.          CloseLibrary(EGBBase);
  101.         }
  102.       CloseLibrary(EGSIntuiBase);
  103.      }
  104. }
  105.